/**
 * @file   routinesO.h
 * @author Carlos Hernández García <carloshergar@usal.es>, Camilo Ruiz, Enrique Conejero
 * @date   Fri Apr  10 2009  
 *
 * Copyright (c) 2009 Carlos Hernández García
 *
 * @brief  This library provides different routines used in the PIC code.
 *
 * 
 * Carlos Hernández García                          \n
 * <carloshergar@usal.es>                             \n
 * Universidad de Salamanca                         \n
 * Plaza de la Merced s/n                           \n
 * E-37008 Salamanca, SPAIN                         \n
 */
/********************************************************************************/


#include <stdio.h>
#include "object.h"

#include "laserfield.h"
//#include "gridobject.h"
//#include "constants.h"


void CalculaRo(particle *_part, cell1d *_cell,double _CalculaRofactor,double _deltag, int _na, int _np, int _ndg, FILE *fp0);
void CalculaJ(int _label, particle *_part, cell1d *_cell,double _CalculaRofactor,double _deltat,double _deltag, int _na, int _np, int _ndg, FILE *fp0, FILE *fp1);

double E0x(double _xg, double _t);
double E0y(double _xg,double _t,double _xgleft, laser &_laser0, int _pulse_shape);
double E0z(double _xg, double _t);
double B0x(double _xg,double _t);
double B0y(double _xg,double _t);
double B0z(double _xg,double _t,double _xgleft, laser _laser0, int _pulse_shape);
void interpola(double _x,cell1d *_cell,double &_Epx,double &_Epy,double &_Epz,double &_Bpx,double &_Bpy,double &_Bpz, double _t,int _ndg,double _deltag, int _na, FILE *fp0);
void ParticleMover(particle &_part, double _Epx,double _Epy,double _Epz,double _Bpx,double _Bpy,double _Bpz, double _deltat, double _lg, int &coolparticles, int n, FILE *fp0);
void CalculaCamposInternos(cell1d *_cell,double _deltat, double _xgleft, laser _laser0, int _ndg, double _deltag, FILE *fp0);

void Charge_deposition (cell1d *_cell, particle &_part, double _deltag, double _factor);
void Current_deposition(cell1d *_cell, particle &_part, double _deltag, double _factor, int n, FILE *f, int _ndg);
void left_one(cell1d *_cell,particle &_part, double _deltag, double _factor, int n, FILE *f);
void left_two_left(cell1d *_cell,particle &_part, double _deltag, double _factor, int n, FILE *f,int _ndg);
void left_two_right(cell1d *_cell,particle &_part, double _deltag, double _factor, int n, FILE *f, int _ndg);
void right_one(cell1d *_cell,particle &_part, double _deltag, double _factor, int n, FILE *f, int _ndg);
void right_two_right(cell1d *_cell,particle &_part, double _deltag, double _factor, int n, FILE *f, int _ndg);
void right_two_left(cell1d *_cell,particle &_part, double _deltag, double _factor, int n, FILE *f, int _ndg);
double gauss_rand48(void);
void InicioVelocidades(particle *_part, int VelocityInit, double Etherm, int _npion, double _vtherm, FILE *fp0);

/*Functions of Version0
void CalculaRo(vector<double> &_xp, grid_object &_ro,vector<double> &_qp,double _deltag, int _na, FILE *fp0);
void CalculaJ(int _label, vector<double> &_xp,vector<double> &_vpx, vector<double> &_vpy,vector<double> &_vpz, grid_object &_Jx,grid_object &_Jy,grid_object &_Jz,vector<double> &_qp,double _deltat,double _deltag, int _na, FILE *fp0, FILE *fp1);


double E0x(double _xg, double _t);
double E0y(double _xg,double _t,double _xgleft, laser &_laser0);
double E0z(double _xg, double _t);
double B0x(double _xg,double _t);
double B0y(double _xg,double _t);
double B0z(double _xg,double _t,double _xgleft, laser _laser0);
void CalculaEx(grid_object & _Ex, grid_object & _Phi, grid_object & _DAx, double _t,double _deltat, FILE *fp0);
void CalculaEy(grid_object & _Ey, grid_object & _DAy,double _t,double _deltat, double _xg,double _xgleft,laser &_laser0);
void CalculaEz(grid_object & _Ez, grid_object & _DAz,double _t,double _deltat);
void CalculaBy(grid_object & _By, grid_object & _Az ,double _t,double _deltat);
void CalculaBz(grid_object & _Bz, grid_object & _Ay ,double _t,double _deltat,double _xg,double _xgleft, laser &_laser0); 
void interpola(double _x,grid_object & _Ex,grid_object & _Ey,grid_object & _Ez,grid_object & _By,grid_object & _Bz,double &_Epx,double &_Epy,double &_Epz,double &_Bpx,double &_Bpy,double &_Bpz, double _t,int _ndg,double _deltag, int _na, FILE *fp0);
void ParticleMover(double &_xp, double &_vpx,double &_vpy, double &_vpz, double _Epx,double _Epy,double _Epz,double _Bpx,double _Bpy,double _Bpz, double _deltat, double ae);
void CalculaPotenciales(grid_object & _phi, grid_object & _Ax, grid_object & _Ay, grid_object & _Az, grid_object & _Axold, grid_object & _Ayold, grid_object & _Azold, grid_object & _DAx, grid_object & _DAy, grid_object & _DAz, grid_object & _Jx, grid_object & _Jy, grid_object & _Jz,grid_object & _IntJx, grid_object & _IntJy, grid_object & _IntJz, grid_object & _Ro, grid_object & _IntRo, grid_object & _Rop, grid_object & _Roold, grid_object & _Ropold, grid_object & _IAxM, grid_object & _IAyM, grid_object & _IAzM, grid_object & _IAxP, grid_object & _IAyP, grid_object & _IAzP, grid_object & _IPhiM, grid_object & _IPhiP, double _deltat, FILE *fp0);
void CalculaCamposInternos(grid_object & _Ex, grid_object & _Ey, grid_object & _Ez, grid_object & _By, grid_object & _Bz, grid_object & _Jx, grid_object & _Jy, grid_object & _Jz, grid_object & _Fp, grid_object & _Fm, grid_object & _Gp, grid_object & _Gm,  double _t,double _deltat, double _xgleft, laser _laser0, FILE *fp0);
*/


